/**
 * Created by aesop on 2015/5/13.
 */

var read_time = 0;
var note_id = location.search.match(/state=[\s\S]+/)[0].slice(6);


var last_record = localStorage.finger_history;
//@TODO 把上次的触摸记录返回
localStorage.finger_history = [];
localStorage.material_id = note_id;
var finger_position =[];
finger_position.__proto__.saved_in_localstorage = function(){
    var that = this;
    localStorage.finger_history = JSON.stringify(that);
}


function single_position(positionX, positionY){
    return {
        x : positionX,
        y : positionY,
        time : (new Date().getTime()).toString()
    }
}
function new_finger_position(x, y){
    finger_position[fingerPosition.length] = single_position(x, y);
    finger_position.saved_in_localstorage();
}

(function count_time(){
    setTimeout(function(){
        read_time +=1;
        //有点太吃资源，但是因为微信坑爹……没办法啊
        $.get("/note/show-online?note_id="+note_id,function(){
            count_time();
        });
    },2000)
})();

//用于记录手指停留位置

document.body.addEventListener("touchstart", function(e){
    e = e || window.event;
    var targetTouches = e.targetTouches;
    if(targetTouches.length == 1){
        new_finger_position(targetTouches[0].pageX, targetTouches[0].pageY);
    }
});


$().ready(function(){
    $.post("/note/pointer-record?note_id="+note_id, {
        record:last_record,
        userAgent:navigator.userAgent
    },function(){
        ;
    })
})
//@TODO 利用jssdk做一些事情